import os
import warnings

import pandas as pd

from MultilabelPredictor import MultilabelPredictor

warnings.filterwarnings('ignore')

data_dir = 'data/GFSAIT/初赛/赛道2：水体/光谱及水体参数数据/训练数据'
models_dir = 'models'

multi_predictor = MultilabelPredictor.load(models_dir)

# 两文件中取后7条作为测试数据进行模型验证
df1 = pd.read_excel(os.path.join(data_dir, '南漪湖-光谱精校验数据.xlsx'), engine='openpyxl').tail(7)
df2 = pd.read_excel(os.path.join(data_dir, '南漪湖-悬浮物+叶绿素数据.xlsx'), sheet_name=1, engine='openpyxl').tail(7)
# 两表合并并去除"序号"、"经度"、"纬度"等不直接参与计算的列
test_df = pd.concat([df1.drop(["序号", "经度", "纬度"], axis=1), df2["悬浮物浓度(mg/L)"], df2["水体叶绿素浓度(ug/L)"]], axis=1)
# 列名中含有中文及/会导致模型存储路径异常，需要改名为ascii
test_df = test_df.rename(columns={"悬浮物浓度(mg/L)": "Seston", "水体叶绿素浓度(ug/L)": "Chlorophyll"})
print(test_df)

# 评估
evaluations = multi_predictor.evaluate(test_df)
print(evaluations)
print("Evaluated using metrics:", multi_predictor.eval_metrics)

# 推理测试
test_df1 = test_df.drop(["Seston", "Chlorophyll"], axis=1)
print(test_df1)

test_df1 = multi_predictor.predict(test_df1)
print("Predictions:  \n", test_df1)